package org.dromara.netbar.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.netbar.domain.vo.NetbarGiftPackLogVo;
import org.dromara.netbar.domain.bo.NetbarGiftPackLogBo;
import org.dromara.netbar.service.INetbarGiftPackLogService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 礼包发放记录
 *
 * @author Lion Li
 * @date 2025-07-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/netbar/giftPackLog")
public class NetbarGiftPackLogController extends BaseController {

    private final INetbarGiftPackLogService netbarGiftPackLogService;

    /**
     * 查询礼包发放记录列表
     */
    @SaCheckPermission("netbar:giftPackLog:list")
    @GetMapping("/list")
    public TableDataInfo<NetbarGiftPackLogVo> list(NetbarGiftPackLogBo bo, PageQuery pageQuery) {
        return netbarGiftPackLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出礼包发放记录列表
     */
    @SaCheckPermission("netbar:giftPackLog:export")
    @Log(title = "礼包发放记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NetbarGiftPackLogBo bo, HttpServletResponse response) {
        List<NetbarGiftPackLogVo> list = netbarGiftPackLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "礼包发放记录", NetbarGiftPackLogVo.class, response);
    }

    /**
     * 获取礼包发放记录详细信息
     *
     * @param packLogId 主键
     */
    @SaCheckPermission("netbar:giftPackLog:query")
    @GetMapping("/{packLogId}")
    public R<NetbarGiftPackLogVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long packLogId) {
        return R.ok(netbarGiftPackLogService.queryById(packLogId));
    }

    /**
     * 新增礼包发放记录
     */
    @SaCheckPermission("netbar:giftPackLog:add")
    @Log(title = "礼包发放记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NetbarGiftPackLogBo bo) {
        return toAjax(netbarGiftPackLogService.insertByBo(bo));
    }

    /**
     * 修改礼包发放记录
     */
    @SaCheckPermission("netbar:giftPackLog:edit")
    @Log(title = "礼包发放记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NetbarGiftPackLogBo bo) {
        return toAjax(netbarGiftPackLogService.updateByBo(bo));
    }

    /**
     * 删除礼包发放记录
     *
     * @param packLogIds 主键串
     */
    @SaCheckPermission("netbar:giftPackLog:remove")
    @Log(title = "礼包发放记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{packLogIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] packLogIds) {
        return toAjax(netbarGiftPackLogService.deleteWithValidByIds(List.of(packLogIds), true));
    }
}
